// ===== char_manager.cpp  (Takuma2 / Serversrc/Server/game/src/char_manager.cpp)
// Fiecare bloc: 'CAUTA' = contextul de dinainte (ancora), 'ADAUGA' = blocul __BATTLE_PASS__.

// ---------- [1] liniile 2334-2500
// CAUTA (context):
		const DESC_MANAGER::DESC_SET& c_ref_set = DESC_MANAGER::instance().GetClientSet();
		std::for_each(c_ref_set.begin(), c_ref_set.end(), RefreshItemShop);
	}
}
#endif

// ADAUGA:
#ifdef __BATTLE_PASS__
#include "text_file_loader.h"
WORD CHARACTER_MANAGER::GetBattlePassTotalEXP(WORD wLevel)
{
	if (wLevel == 0)
		return 100;
	
	auto iter = m_map_battle_pass_max_exp.find(wLevel);
	if (iter != m_map_battle_pass_max_exp.end())
		return iter->second;

	return 0;
}

void CHARACTER_MANAGER::LoadConfigBattlePass()
{
	if (g_bAuthServer)
		return;
	
	m_vec_battle_pass.clear();
	m_map_battle_pass_max_exp.clear();
	m_vec_battle_pass_rewards.clear();
	
	CTextFileLoader loader;

	char c_pszFileName[156];
	snprintf(c_pszFileName, sizeof(c_pszFileName), "locale/europe/config_systems/battle_pass.txt");

	if (!loader.Load(c_pszFileName))
		return;
	
	std::string stName;
	
	for (DWORD i = 0; i < loader.GetChildNodeCount(); ++i)
	{
		loader.SetChildNode(i);
		loader.GetCurrentNodeName(&stName);

		int is_rewards_config = 0;
		loader.GetTokenInteger("is_config", &is_rewards_config);
		
		if (is_rewards_config == 1)
		{
			char buf[32 + 1];
			
			TTokenVector * pTok;
			for (int k = 1; k < 30; ++k)
			{
				snprintf(buf, sizeof(buf), "free_%d", k);
				if (loader.GetTokenVector(buf, &pTok))
				{
					int vnum = 0; int count = 0; int iNecessaryLevel = 0;
					str_to_number(vnum, pTok->at(0).c_str());
					str_to_number(count, pTok->at(1).c_str());
					str_to_number(iNecessaryLevel, pTok->at(2).c_str());
				
					SInfoRewardBattlePass sMissionR;		
					sMissionR.vnum = vnum;
					sMissionR.count = count;
					sMissionR.iNecessaryLevel = iNecessaryLevel;
					sMissionR.bIsForPremium = false;
					
					m_vec_battle_pass_rewards.push_back(sMissionR);
				}
				
				snprintf(buf, sizeof(buf), "premium_%d", k);
				if (loader.GetTokenVector(buf, &pTok))
				{
					int vnum = 0; int count = 0; int iNecessaryLevel = 0;
					str_to_number(vnum, pTok->at(0).c_str());
					str_to_number(count, pTok->at(1).c_str());
					str_to_number(iNecessaryLevel, pTok->at(2).c_str());
				
					SInfoRewardBattlePass sMissionR;		
					sMissionR.vnum = vnum;
					sMissionR.count = count;
					sMissionR.iNecessaryLevel = iNecessaryLevel;
					sMissionR.bIsForPremium = true;
					
					m_vec_battle_pass_rewards.push_back(sMissionR);
				}
				
				snprintf(buf, sizeof(buf), "max_exp_lv_%d", k);
				if (loader.GetTokenVector(buf, &pTok))
				{
					int iMaxEXP = 0;
					str_to_number(iMaxEXP, pTok->at(0).c_str());
					m_map_battle_pass_max_exp[k] = iMaxEXP;
				}
				
			}
		}
		else
		{
			int iType = 0;
			if (!loader.GetTokenInteger("type", &iType))
			{
				sys_err("ReadBattlePassTable : Syntax error %s : no type, node %s", c_pszFileName, stName.c_str());
				loader.SetParentNode();
				return;
			}

			int iUniqueMissionID = 0;
			if (!loader.GetTokenInteger("mission_id", &iUniqueMissionID))
			{
				sys_err("ReadBattlePassTable : Syntax error %s : no mission_id, node %s", c_pszFileName, stName.c_str());
				loader.SetParentNode();
				return;
			}

			int category_mission = 0;
			if (!loader.GetTokenInteger("category", &category_mission))
			{
				sys_err("ReadBattlePassTable : Syntax error %s : no category, node %s", c_pszFileName, stName.c_str());
				loader.SetParentNode();
				return;
			}

			int is_premium = 0;
			if (!loader.GetTokenInteger("is_premium", &is_premium))
			{
				sys_err("ReadBattlePassTable : Syntax error %s : no is_premium, node %s", c_pszFileName, stName.c_str());
				loader.SetParentNode();
				return;
			}

			int iVnum = 0;
			if (!loader.GetTokenInteger("vnum", &iVnum))
			{
				sys_err("ReadBattlePassTable : Syntax error %s : no vnum, node %s", c_pszFileName, stName.c_str());
				loader.SetParentNode();
				return;
			}

			int iCount = 0;
			if (!loader.GetTokenInteger("count", &iCount))
			{
				sys_err("ReadBattlePassTable : Syntax error %s : no count, node %s", c_pszFileName, stName.c_str());
				loader.SetParentNode();
				return;
			}

			int iEXP = 0;
			if (!loader.GetTokenInteger("exp", &iEXP))
			{
				sys_err("ReadBattlePassTable : Syntax error %s : no exp, node %s", c_pszFileName, stName.c_str());
				loader.SetParentNode();
				return;
			}

			SInfoBattlePassConfig sMission;
			
			sMission.type = iType;
			sMission.iUniqueMissionID = iUniqueMissionID;
			sMission.bIndexCategory = category_mission;
			sMission.is_premium = is_premium;
			sMission.vnum  = iVnum;
			sMission.count = iCount;
			sMission.iEXP = iEXP;

			m_vec_battle_pass.push_back(sMission);
		}

		loader.SetParentNode();
	}
}
#endif
// (context dupa)


